<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
	<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
	<title></title>
	<script type="text/javascript" src="../../js/boot.js"></script>
</head>

<body>
	<div style="width:100%;height:60%;">
		<fieldset id="fd1" style="width: 97%; margin-bottom: 10px;">
			<div id="dayForm" style="padding:10px;">
				<input name="dayReportID" class="mini-hidden" enabled="false">
				<table align="center">
					<tr>
						<td align="right">用户姓名：</td>
						<td align="left"><input name="userName" class="mini-textbox" enabled="false"></td>
						<td align="right">部门名称：</td>
						<td align="left"><input name="departName" class="mini-textbox" enabled="false"></td>
						<td align="right">日期：</td>
						<td align="left"><input name="calendarDate" class="mini-textbox" enabled="false"></td>
					</tr>
					<tr>
						<td align="right">日期类型：</td>
						<td align="left"><input name="dayType" class="mini-textbox" enabled="false"></td>
						<td align="right">刷卡记录：</td>
						<td align="left" colspan="3"><input name="cardRecord" class="mini-textbox" width="400" enabled="false"></td>
					</tr>
					<tr>
						<td align="right">排班上班时间：</td>
						<td align="left"><input name="startWorkTime" class="mini-datepicker" format="yyyy-MM-dd HH:mm" enabled="false"></td>
						<td align="right">排班下班时间：</td>
						<td align="left" colspan="3"><input name="endWorkTime" class="mini-datepicker" format="yyyy-MM-dd HH:mm" enabled="false"></td>
					</tr>
					<tr>
						<td align="right">实际上班时间：</td>
						<td align="left"><input name="recordStartWorkTime" class="mini-datepicker" format="yyyy-MM-dd HH:mm" enabled="false"></td>
						<td align="right">实际下班时间：</td>
						<td align="left" colspan="3"><input name="recordEndWorkTime" class="mini-datepicker" format="yyyy-MM-dd HH:mm" enabled="false"></td>
					</tr>
					<tr>
						<td align="right">工作时长：</td>
						<td align="left"><input id="workTime" name="workTime" class="mini-spinner" increment="0.5" minValue="0"></td>
						<td align="right">加班时长：</td>
						<td align="left"><input id="overTime" name="overTime" class="mini-spinner" increment="0.5" minValue="0"></td>
						<td align="right">请假时长：</td>
						<td align="left"><input id="applyTime" name="applyTime" class="mini-spinner" increment="0.5" minValue="0"></td>
					</tr>
					<tr>
						<td align="right">提交时间：</td>
						<td align="left"><input name="submitTime" class="mini-datepicker" format="yyyy-MM-dd HH:mm" enabled="false"></td>
						<td align="right">提交备注：</td>
						<td align="left" colspan="3"><input id="submitRemark" name="submitRemark" class="mini-textbox" width="400"></td>
					</tr>
					<tr>
						<td align="right">审核时间：</td>
						<td align="left"><input name="checkedTime" class="mini-datepicker" format="yyyy-MM-dd HH:mm" enabled="false"></td>
						<td align="right">审核备注：</td>
						<td align="left" colspan="3"><input id="checkRemark" name="checkRemark" class="mini-textbox" width="400"></td>
					</tr>
				</table>
			</div>
		</fieldset>
	</div>

	<div style="width:100%;height:40%;">
		<fieldset id="fd1" style="width: 97%; margin-bottom: 10px;">
			<div id="detailForm" style="padding:10px;">
				<table align="center">
					<tr>
						<td align="right">工时分项：</td>
						<td align="left">
							<div id="projectSortID" name="projectSortID" class="mini-radiobuttonlist" repeatLayout="table" textField="text" valueField="id"
								width="360">
							</div>
						</td>
						<td align="right">项目名称：</td>
						<td align="left">
							<div id="projectID" name="projectID" class="mini-combobox" style="width:240px;" popupWidth="300" textField="projectName"
								valueField="projectID" showClose="true" oncloseclick="onCloseClick">
								<div property="columns">
									<div header="项目编号" field="projectNo"></div>
									<div header="项目名称" field="projectName"></div>
								</div>
							</div>
						</td>
					</tr>
					<tr>
						<td align="right">出勤分类：</td>
						<td align="left">
							<div id="workSort" name="workSort" class="mini-radiobuttonlist" repeatLayout="table" textField="text" valueField="id"
								data="workSortData" width="360">
							</div>
						</td>
						<td align="right">工作时长：</td>
						<td align="left"><input name="workTime" class="mini-spinner" increment="0.5" minValue="0.5" maxValue="12" width="240"></td>
					</tr>
					<tr>
						<td align="right">工作说明：</td>
						<td align="left" colspan="3"><input name="description" class="mini-textbox" width="500"></td>
					</tr>
				</table>
			</div>
			<div property="footer" style="text-align:center;padding:5px;padding-right:15px;">
				<a class="mini-button" iconCls="icon-save" id="doSave" onClick="doSave()">保存</a>
				<a class="mini-button" iconCls="icon-cancel" onClick="closeWindow('ok')">取消</a>
			</div>
		</fieldset>
	</div>

</body>

<script type="text/javascript">
	var localUser = null;
	var userID = null;
	var obj = localStorage.getItem('user');
	if (obj) {
		localUser = mini.decode(obj);
		userID = localUser.userID;
	}

	var workSortData = [
		{ id: 1, text: "正常出勤" },
		{ id: 2, text: "正常加班" },
		{ id: 3, text: "周末加班" },
		{ id: 4, text: "假日加班" }
	];

	miniInit();

	var dayForm = new mini.Form("#dayForm"); // 日报属性页
	var detailForm = new mini.Form("#detailForm"); // 工作日报的子项属性页

	// 工时分项
	var projectSortID_WORK = null; // 项目工时的主键
	var projectSortID_DEPART = null; // 部门工时的主键
	var projectSortData = [];
	var rblProjectSort = mini.get("projectSortID");
	http.getSync("/oa/project/sort/list.do", function (page) {
		if (page.data.length > 0) {
			var list = page.data;
			// debugger
			for (var i = 0; i < list.length; i++) {
				if (list[i].sortName == "项目工时") {
					projectSortID_WORK = list[i].projectSortID;
				} else if (list[i].sortName == "部门工时") {
					projectSortID_DEPART = list[i].projectSortID;
				}
			}
			projectSortData = [
				{ id: projectSortID_DEPART, text: "部门工时" },
				{ id: projectSortID_WORK, text: "项目工时" }
			];
			rblProjectSort.setData(projectSortData);
			// 延时设置值，否则不起作用
			/* setTimeout(function () {
				rblProjectSort.setValue(projectSortID_DEPART);
				projectCombox.setEnabled(false);
				projectCombox.setText("");
				projectCombox.setValue("");
			}, 2000); */
		}
	});

	// 当选择项目工时，项目名称是必选项；选择部门工时时，项目名称禁止填写
	rblProjectSort.on("valuechanged", function (e) {
		if (rblProjectSort.getValue() == projectSortID_WORK) {
			projectCombox.setEnabled(true);
		} else {
			projectCombox.setEnabled(false);
			projectCombox.setText("");
			projectCombox.setValue("");
		}
	});

	// 项目名称控件数据
	var projectCombox = mini.get("projectID");
	var projectUrl = "/oa/project/project/list.do?status=1&orderBy=projectNo";
	if (userID != null) {
		projectUrl = projectUrl + "&userID=" + userID;
	}
	var projectData = [];
	http.getSync(projectUrl, function (page) {
		if (page.data.length > 0) {
			projectCombox.setData(page.data);
			for (var i = 0; i < page.data.length; i++) {
				projectData.push({ id: page.data[i].projectID, text: page.data[i].projectName });
			}
		}
	});

	var dayReportID_ = null;
	var projectDayID_ = null;
	// 初始化加载数据
	function setData(dayReportID, projectDayID) {
		dayReportID_ = dayReportID;
		projectDayID_ = projectDayID;
		var dayReport = null;
		// 加载日报数据
		http.getSync("/day/report/getDayReport.do?dayReportID=" + dayReportID, function (page) {
			if (page.success) {
				dayReport = page.data;
				dayForm.setData(dayReport);
				// debugger
				// 如果不是本用户的数据，则保存和提交按钮不可用
				if (localUser.userID != dayReport.userID) {
					mini.get("doSave").setEnabled(false);
				}
				// 如果提交状态不是未提交，则保存和提交按钮不可用
				if (dayReport.checkStatus > 0) {
					mini.get("doSave").setEnabled(false);
				}
			}
		});
		// 加载日报明细数据
		if (projectDayID) {
			http.get("/day/report/getDayReportDetail.do?projectDayID=" + projectDayID, function (page) {
				if (page.success) {
					// debugger
					var bean = page.data;
					detailForm.setData(bean);
				}
			});
		} else {
			// 如果工作没有数据，那么就是新增。加载默认设置
			rblProjectSort.setValue(projectSortID_DEPART);
			projectCombox.setEnabled(false);
			projectCombox.setText("");
			projectCombox.setValue("");
			debugger
			// 工作日，假日，节日
			var workSort = 0;
			if (dayReport.dayType == null || dayReport.dayType == "工作日") {
				// 如果工作超过8小时，自动选择加班
				if (dayReport.totalWorkTime >= 8) {
					workSort = 2;
				} else {
					workSort = 1;
				}
			} else if (dayReport.dayType == "假日") {
				workSort = 3;
			} else if (dayReport.dayType == "节日") {
				workSort = 4;
			}
			mini.get("workSort").setValue(workSort);
		}
	}

	// 保存
	function doSave() {
		var data = detailForm.getData(true, false);
		if (data.workTime <= 0) {
			miniui.showErrorMessageBox("工作时长必须大于0！");
			return;
		}
		miniui.mask('数据保存中...');
		data.dayReportID = dayReportID_;
		data.projectDayID = projectDayID_;
		data.userID = userID;
		data.workType = 1; // 非技术部门提交的永远是出勤工时记录
		var day = dayForm.getData(true, false);
		data.calendarDate = day.calendarDate;
		// debugger
		http.post("/day/report/saveDayReportDetail.do", data, function (page) {
			mini.unmask();
			miniui.showPageMessageBox(page, "保存成功！", function () {
				closeWindow("ok");
			});
		});
	}

	function closeWindow(action) {
		if (window.CloseOwnerWindow)
			return window.CloseOwnerWindow(action);
		else
			window.close();
	}
</script>

</html>